home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / TWEAKDOC.ZIP / TWEAKDOC.TXT < prev   
Text File  |  1995-12-17  |  13KB  |  294 lines

  1.  
  2.               ╒═══════════                          ═══════════╕
  3.               │                                                │
  4.               │        -=≡  O∙U∙T∙L∙A∙W  T∙R∙I∙A∙D  ≡=-        │
  5.  
  6.                                  ■ Presents ■
  7.  
  8.  
  9.                    ■ TWEAKING THE VIDEOMODE 13h INTO MODEX ■
  10.               │                                                │
  11.               │                                                │
  12.               ╘═══════  Copyright Outlaw Triad (C) 1995  ══════╛
  13.  
  14.  
  15. ───────────────────────────────────────────────────────────────────────────────
  16.   Written By : Vulture/OT                 Total Files  : 2
  17.   File Type  : Textfile                   Release Date : 17th of December '95
  18.   Difficulty : Hard level                 Filename     : TWEAKDOC.ARJ
  19. ───────────────────────────────────────────────────────────────────────────────
  20.  
  21. Hello there! Vulture here typing another document on vga-programming.
  22.  
  23. Some time ago I wrote and released a textfile (CHAINDOC.ARJ) on the unchained
  24. vgamode 13h. In this document I (tried to) explain it is possible to use the
  25. 256kB on the standard vga-card in mode 13h. To do this, one must unchain the
  26. videomode. This gives us a resolution of 320*200*256 and 4 pages in display
  27. memory. I also stated that it is possible to tweak the unchained videomode
  28. into other resolutions. The way you handle a tweaked mode is the same as in
  29. a standard unchained mode but you can get different resolutions to work with.
  30.  
  31. This document shows how to get into the ModeX, the mode which was 'invented'
  32. by Michael Abrash in his columns printed in Dr Dobbs Journal. This mode has
  33. a resolution of 320*240*256 which gives us 3 pages to work with and besides
  34. that, it gives us a perfect square pixel. This eliminates the rectangular
  35. pixels in standard mode 13h or standard unchained videomode. It is also
  36. possible to get in even higher resolutions like 320*400*256. I will explain
  37. that too. Full assembler source is included in this document. Enjoy!
  38.  
  39. ───────────────────────────────────────────────────────────────────────────────
  40.  
  41. The topics handled in this document will be:
  42.  
  43.  A. How to get into modex.
  44.  B. Assembler code for modex.
  45.  C. Other modes.
  46.  D. Closing words.
  47.  
  48. ───────────────────────────────────────────────────────────────────────────────
  49.  
  50. - A. HOW TO GET INTO MODEX -
  51.  
  52. It is possible to tweak the vga-mode 13h into other resolutions. In order
  53. to do this, one must first unchain the vgamode. This gives us the normal
  54. unchained vga-mode with 4 pages of display memory. We then alter some vga
  55. registers to get into a higher (or lower) resolution. For plasma you could
  56. use a low resolution so you have to process less pixels. This gives more
  57. speed to your demo. When displaying a picture, you could use a higher mode.
  58. To get a different resolution to work with, you must reprogram the CtrC
  59. Register. A total of 10 CrtC indexes must be updated. This can be done using
  60. the OUT statement in assembler. First you select the CrtC Adress Register.
  61. This is port 03d4h. Then select an index and give it the appropiate data.
  62. The index and data values both are bytes. Two bytes are a word so you can
  63. store the values into 1 register. In our case we'll use AX. Store the index
  64. value into AL, the data into AH, out AX to the CrtC Register and you're done!
  65. E.g 00d06h would mean index 06h (loaded in AL) and data 00dh (loaded in AH).
  66. Do this for all 10 registers which must be updated. Piece of cake, eh?
  67. Once you know what you're doing...
  68.  
  69. In the following diagram you can see which indexes must be altered and what
  70. data should be transfered to these indexes. To fully understand what is done
  71. when altering these registers, read a good book on vga-programming. If I go
  72. and explain all of it in here, you would get a book anyway... ;-)
  73.  
  74. (Note: To get a better overview I have converted the hexdecimal value to
  75. normal decimal values and their bitrepresentation. So one can see which bits
  76. in the index are set and unset. I did this primarily for myself coz I had a
  77. very hard time understanding the hex-code with both the index AND data in
  78. them. Hopefully this will prefend you from having the same troubles I had.
  79. Btw, there might be some errors in the convertion coz it's the first time
  80. I did these things. And my math really stinks... ;-) )
  81.  
  82. - Diagram 1 -
  83.  
  84.        Index   │ Data in hex  │  decimal   │   binair
  85.      ──────────┼──────────────┴────────────┴────────────
  86.          6h    │    00dh      =    13d     =  00001101b
  87.          7h    │    03eh      =    62d     =  00111110b
  88.          9h    │    041h      =    65d     =  01000001b
  89.          10h   │    0eah      =   234d     =  11101010b
  90.          11h   │    0ach      =   172d     =  10101100b
  91.          12h   │    0dfh      =   223d     =  11011111b
  92.          14h   │    000h      =     0d     =  00000000b
  93.          15h   │    0e7h      =   231d     =  11100111b
  94.          16h   │    006h      =     6d     =  00000110b
  95.          17h   │    0e3h      =   227d     =  11100011b
  96.  
  97. One can easily make these values accesable by using a label. As stated before,
  98. the lower 2 values of the word represent the index we want to access while the
  99. upper 3 values are representing the data that is being shifted to the selected
  100. index. This is demonstrated here:
  101.  
  102. Label 320x240x256 Word      ; Index/data pairs for modex
  103.   DW 00d06h     ; Vertical Total (first 8 bits)
  104.   DW 03e07h     ; Overflow (ninth/tenth bit Vertical Total)
  105.   DW 04109h     ; Cellheight (2)
  106.   DW 0ea10h     ; Vertical Retrace Start
  107.   DW 0ac11h     ; Vertical Retrace End & (un)protect registers 0-7
  108.   DW 0df12h     ; Vertical Display End
  109.   DW 00014h     ; Underline Location (disable dword mode)
  110.   DW 0e715h     ; Start Vertical Blank
  111.   DW 00616h     ; End Vertical Blank
  112.   DW 0e317h     ; Mode Control (enable byte mode)
  113.  
  114. Reprogram (tweak) the Crt Controller Register with these values like this:
  115.  
  116.     xor     ax,ax        ; Empty ax
  117.     mov     dx,03d4h     ; CrtC Register
  118.     mov     cx,10        ; Number of entries
  119.     mov     si,offset 320x240x256    ; Set ds:si to offset data
  120. ParamLoop:
  121.     lodsw                ; Load pair of index/data values into ax
  122.     out     dx,ax        ; Out them to CrtC Register
  123.     loop    ParamLoop
  124.  
  125. But before one can out these values, one must remove the write protection
  126. on CrtC registers 0-7. Also set the dot-clock which can be either 0e3h
  127. (for low res) or 0e7h (for high res).
  128. Once you've done all this, clear the display memory and set the logical
  129. screenwidth. The total ModeX setting code now looks like this:
  130.  
  131. ───────────────────────────────────────────────────────────────────────────────
  132.  
  133. - B. ASSEMBLER CODE FOR MODEX -
  134.  
  135. This code sets the 'official' modeX 320x240x256 with 3 pages.
  136. Some things can be speed up but I'll leave that up to you.
  137.  
  138. ; === Sequencer Registers ===
  139.  
  140. Seq_Index   =  3C4h   ; Sequencer Registers Adress
  141. CrtC_Index  =  3D4h   ; CRTC Adress Register
  142. Graph_Index =  3CEh   ; Graphics Adress Register
  143. Attr_Index  =  3C0h   ; Atribute Controller Write
  144.  
  145. SetModeX PROC NEAR           ; Sets the ModeX 320*240*256
  146. ; === Set normal Mode 13h ===
  147.     mov     ax,0013h         ; Videomode 13h  320*200*256
  148.     int     10h              ; Set the mode
  149.  
  150. ; === Disable chain4 bit ===
  151.     mov     dx,Seq_Index     ; Sequencer Address Register
  152.     mov     al,04h           ; Index 4 - Memory mode
  153.     out     dx,al
  154.     inc     dx               ; 03c5h - Data register => set the mem mode here
  155.     in      al,dx
  156.     and     al,11110111b     ; Disable 3rd bit will give us unchained memory
  157.     or      al,00000100b     ; Bit 2 enabled => no odd/even-scheme
  158.     out     dx,al
  159.  
  160. ; === Set dot clock & scanning rate ===
  161.     mov     ax,0100h
  162.     out     dx,ax            ; Stop sequencer while setting Misc Output
  163.  
  164.     mov     dx,Misc_Output
  165.     mov     al,0e3h          ; 0e3h = 227d = 11100011b
  166.     out     dx,al            ; Select 25 MHz dot clock & 60 Hz scanning rate
  167.  
  168.     mov     dx,Seq_Index
  169.     mov     ax,0300h         ; Index 00h --- 03h = 3d = 00000011b
  170.     out     dx,ax            ; Undo reset (restart sequencer)
  171.  
  172. ; === Remove write protection ===
  173.     mov     dx,CrtC_Index
  174.     mov     al,11h           ; VSync End contains write protect bit (bit 7)
  175.     out     dx,al
  176.     inc     dx               ; Crt Controller Data register
  177.     in      al,dx
  178.     and     al,01111111b     ; Remove write protect on various CrtC registers
  179.     out     dx,al            ; (bit 7 is 0)
  180.  
  181. ; === Initialize ModeX ===
  182.     cld                      ; Clear direction flag (si increased)
  183.     xor     ax,ax            ; Empty ax
  184.     mov     dx,CrtC_Index    ; Port 03d4h
  185.     mov     cx,10            ; Number of entries
  186.     mov     si,offset 320x240x256
  187. ParamLoop:
  188.     lodsw                    ; Load pair of index/data values
  189.     out     dx,ax            ; Out them to CrtC Register
  190.     loop    ParamLoop
  191.  
  192. ; === Clear VGA memory ===
  193.     mov     dx,Seq_Index     ; Select port 03c4h
  194.     mov     ax,00f02h        ; Map Mask Register (select all planes)
  195.     out     dx,ax
  196.     mov     ax,0a000h        ; VGA segment
  197.     mov     es,ax
  198.     xor     di,di            ; Set es:di to point to screenmem  di=0
  199.     xor     ax,ax            ; Color to store = usually black = 0
  200.     mov     cx,32768         ; 32768 (words) * 2 = 65536 bytes = 1 plane
  201.     cld                      ; Clear dirflag => di is increased
  202.     rep     stosw            ; Clear all 4 planes using wordwrites
  203.  
  204. ; === Set logical screenwidth ===
  205.     mov     dx,CrtC_Index    ; CrtC registers
  206.     mov     al,13h           ; Index Logical screenwidth
  207.     mov     ah,40            ; 1 page width & 3 pages in height
  208.     out     dx,ax
  209.  
  210.     ret
  211. SetModeX ENDP
  212.  
  213. And that's it! As you can see, you have to do a lot before you are in gfx
  214. mode. But it is well worth the effort.
  215.  
  216. ───────────────────────────────────────────────────────────────────────────────
  217.  
  218. - C. OTHER MODES -
  219.  
  220. It is possible to create a large scale of different resolutions. The following
  221. combinations will set a resolution of 320*400*256. Nice for pictures and stuff!
  222.  
  223. Label 320x400x256
  224.   DW 04009h     ; Cellheight (1)
  225.   DW 00014h     ; Underline Location (disable dword mode)
  226.   DW 0e317h     ; Mode Control (enable byte mode)
  227.  
  228. In this mode, all you have to do is set the cellheight to 1. The normal
  229. cellheight is 2 which means that every single scanline (Yline) is written
  230. to the screen twice. So if you make it 1, the monitor will only show 1 line
  231. instead of 2. Thus we get a resolution of 320*400*256 with 2 pages available
  232. in display memory.
  233.  
  234. I will not get into other resolutions at this time. Primarily coz I have to
  235. study these modes first ;-) and secondly ... the normal modex and the highres
  236. of 320*400 are enough to get started with, IMHO.
  237.  
  238. ───────────────────────────────────────────────────────────────────────────────
  239.  
  240. D. CLOSING WORDS.
  241.  
  242. This document was written by Vulture / Outlaw Triad.
  243.  
  244. Thanks must go to Michael Abrash for explaining things and Draeden of VLA for
  245. example source-code. Also thanks to Denthor of Asphyxia for releasing code to
  246. this subject (allthough I think Denthor needs to be a little more specific on
  247. things).
  248.  
  249. One more thing... if you really want to get into this stuff, buy a good book
  250. on the subject. I recomment "Programmers Guide to the EGA, VGA and SuperVGA
  251. Cards" from Richard F. Ferraro. It provides detailed explanation of all the
  252. vga-registers. A real "must have"! (Damn, I should get paid for this ;-) )
  253.  
  254. Legal crap: Outlaw Triad accepts no responsibility for damage occured when
  255. using this piece of software. Yo, it's free stuff, dudez! We've used this
  256. code (in a modified form) ourselves and didn't have any troubles with it.
  257.  
  258. If you want to contact Outlaw Triad for some reason, call our distro-sites
  259. and leave a message to Vulture. Or leave e-mail at: comma400@tem.nhl.nl
  260. Visit our internet homepage at: http://www.nhl.nl/~comma400/vulture.html
  261. These internet adresses should be valid at least till June 1996.
  262.  
  263. Outlaw is looking for another graphic artist to do some graphics for the
  264. intros we want to create. Leave mail to Vulture.
  265.  
  266.  Ok, this is it, bye...
  267.  
  268.          Vulture / Outlaw Triad
  269.  
  270. ───────────────────────────────────────────────────────────────────────────────
  271.                                 OUTLAW DISTROS
  272.  
  273.   ■     The Force     ■      ■   Blue Nose Prod  ■     ■     FireHouse     ■
  274.   ■ +31 (0)36-5346967 ■      ■ +31 (0)345-619401 ■     ■ +31 (0)528-274176 ■
  275.  
  276.                                 Open For More!
  277. ───────────────────────────────────────────────────────────────────────────────
  278.                                 OUTLAW GREETZ (in no order)
  279.  
  280.   Personal:
  281.  
  282.   DemoLisher (he-ya dude), MadMan (you're mad), Xotic (you make real
  283.   cool gfx, man), Utter Chaos (at full speed), ThunderHawk (goodluck
  284.   coding gfx), Silencer (ya making gfx?), Crusher (too bad you quit),
  285.   all contacts on internet (you know who U R), and all otha people
  286.   we know ... Bye!
  287.  
  288.   Groups:
  289.  
  290.   Chiparus, Acme, Inertia and all other demo-groups around...
  291. ───────────────────────────────────────────────────────────────────────────────
  292.  
  293.  
  294.            ■ Outlaw Triad quote: "Let's make things understandable" ■